//
//  Bi BindingNetwayView.m
//  YSSmartHome
//
//  Created by Yahaong on 16/8/24.
//  Copyright © 2016年 yahaong. All rights reserved.
//

#import "BindingGatewayView.h"
#import "MitRegex.h"
#import "XAIGateway.h"
//#include <openssl/sha.h>
#import "MQTTCoverTool.h"
#import <XAISDK/XAIBroadcastPack.h>
@interface BindingGatewayView ()
@property(nonatomic, strong)UILabel     *m_lblTitle;
@property(nonatomic, strong)UILabel     *m_lblGetway;
@property(nonatomic, strong)UITextField *m_textGetway;
@property(nonatomic, strong)UIButton    *m_btnSure;
@end
@implementation BindingGatewayView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.m_lblTitle];
    [self.m_lblTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self).offset(kIphoneSize_Height(10));
    }];
    UIView *splitView = [[UIView alloc]init];
    splitView.backgroundColor = RGBColor(233, 233, 233);
    [self addSubview: splitView];
    [splitView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.m_lblTitle.bottom).offset(kIphoneSize_Height(10));
        make.height.equalTo(1);
        make.leading.trailing.equalTo(self);
    }];
    [self addSubview:self.m_lblGetway];
    [self.m_lblGetway mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(kIphoneSize_Widith(15));
        make.top.equalTo(splitView.bottom).offset(kIphoneSize_Height(10));
        
    }];
    [self addSubview:self.m_textGetway];
    [self.m_textGetway mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.m_lblGetway);
        make.top.equalTo(self.m_lblGetway.bottom).offset(kIphoneSize_Height(10));
        make.trailing.equalTo(self).offset(-kIphoneSize_Widith(15));
        make.height.equalTo(kIphoneSize_Height(50));
    }];
    [self addSubview:self.m_btnSure];
    [self.m_btnSure mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.m_textGetway.bottom).offset(kIphoneSize_Height(10));
        make.trailing.leading.equalTo(self.m_textGetway);
        make.height.equalTo(self.m_textGetway);
    }];
    
}



#pragma mark - action
- (void)sure
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(sureBtnClick:)]) {
        [self.delegate sureBtnClick:self.m_textGetway.text ];
    }
}

#pragma mark - lazy loading
- (UILabel *)m_lblTitle
{
    if (!_m_lblTitle) {
        _m_lblTitle = [[UILabel alloc]init];
        _m_lblTitle.textColor = RGBColor(51, 51, 51);
        _m_lblTitle.font = [UIFont systemFontOfSize:20];
        _m_lblTitle.text = @"验证绑定网关";
    }
    return _m_lblTitle;
}
- (UILabel *)m_lblGetway
{
    if (!_m_lblGetway) {
        _m_lblGetway = [[UILabel alloc]init];
        _m_lblGetway.textColor = RGBColor(51, 51, 51);
        _m_lblGetway.font = [UIFont systemFontOfSize:16];
        _m_lblGetway.text = @"网关名称";
    }
    return _m_lblGetway;
}
- (UITextField *)m_textGetway
{
    if (!_m_textGetway) {
        _m_textGetway = [[UITextField alloc]init];
        _m_textGetway.backgroundColor = kBgColor;
        _m_textGetway.placeholder = @"请为你的网关命名";
    }
    return _m_textGetway;
}


- (UIButton *)m_btnSure
{
    if (!_m_btnSure) {
        _m_btnSure = [[UIButton alloc]init];
        [_m_btnSure setBackgroundImage:[UIImage imageNamed:@"circleBtnbg"] forState:UIControlStateNormal];
        [_m_btnSure setTitle:@"确定" forState:UIControlStateNormal];
        [_m_btnSure addTarget:self
                     action:@selector(sure) forControlEvents:UIControlEventTouchUpInside];
    }
    return _m_btnSure;
}
@end
